import java.util.ArrayList;
import java.util.Iterator;

public class MinStack {
    ArrayList<Integer> list;
    int mount;
    public MinStack() {
        list=new ArrayList<>();
        mount =-1;
    }

    public void push(int x) {
        list.add(x);
        mount++;
    }

    public void pop() {
        list.remove(mount);
        mount--;
    }

    public int top() {
        return list.get(mount);
    }

    public int getMin() {
        if(mount==-1)return 0;
        else {
            Iterator<Integer> iterator=list.iterator();
            int min=iterator.next();
            while (iterator.hasNext()){
                int temp=iterator.next();
                if(temp<min) min=temp;
            }
            return min;
        }
    }
}
